package mylab.io.store.rxtx;

import io.netty.buffer.ByteBuf;
import io.netty.handler.codec.ByteToMessageDecoder;
import lombok.experimental.UtilityClass;
import mylab.io.base.model.Msg;
import mylab.io.core.codec.MsgResolver;
import mylab.io.core.context.DefaultCC;
import mylab.io.store.rxtx.property.RxtxProperties;

@UtilityClass
public class RxtxExpress {

    /**
     * 快速创建 RxtxPipe
     */
    public <M extends Msg> RxtxDas<M> create(RxtxProperties rxtxPropertites,
                                             Class<? extends ByteToMessageDecoder> frameDecoderClass,
                                             MsgResolver<M, ByteBuf> msgResolver) {
        DefaultCC<RxtxProperties, M> cc = context(rxtxPropertites);
        RxtxCodec<M> codec = new RxtxCodec<>(cc, msgResolver, frameDecoderClass);
        return new RxtxDas<>(cc, codec);
    }

    <M extends Msg> DefaultCC<RxtxProperties, M> context(RxtxProperties opcProperties) {
        return new DefaultCC<>(opcProperties);
    }


}
